<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>Form Validation</title>

    <div th:include="commons :: comhead"></div>
</head>

<body class="sticky-header">

<section>
    <!-- left side start-->
    <div th:replace="commons :: #left"></div>
    <!-- left side end-->

    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <div th:replace="commons :: #search"></div>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                商品
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">主页</a>
                </li>
                <li class="active">行政管理</li>
                <li class="active">提交商品信息</li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            商品信息
                        </header>
                        <div class="panel-body">
                            <form role="form" class="form-horizontal adminex-form" th:action="@{/off_add}" method="post" onsubmit="return check(this)">
                                <div class="form-group has-success">
                                    <label class="col-lg-2 control-label">商品名</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="itemName" class="form-control" >
                                    </div>
                                </div>
                                <div class="form-group has-success">
                                    <label class="col-lg-2 control-label">商品价格</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="itemPrice" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-error">
                                    <label class="col-lg-2 control-label">商品数量</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="itemCount" class="form-control" >
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-offset-2 col-lg-10">
                                        <button class="btn btn-primary" type="submit">Submit</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </section>
                </div>
            </div>
        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2020 &copy; AdminEx by ThemeBucket </a>
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<div th:replace="commons :: js"></div>

<!--common scripts for all pages-->
<script>
    function check(f){
        var name= f.itemName.value;
        var count = f.itemCount.value;
        var price = f.itemPrice.value;
        var reg1 =/[\u4e00-\u9fa5_a-zA-Z_]/
        var reg2 =/^[+]{0,1}(\d+)$/
        var reg3 =/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/
        if(name==""||count==""||price==""){
            alert("商品名和单价和数量都不能为空");
            return false;
        }else if(!reg1.test(name)){
            alert("请输入中文或者字母形式的商品名")
            return false;
        }else if(!reg2.test(count)){
            alert("请在此输入正整数形式的数量")
            return false;
        }else if(!reg3.test(price)){
            alert("请在此输入正数形式的价格")
            return false;
        }else if(price==0){
            alert("价格不能为0")
            return false;
        }else{
            return true
        }
    }
</script>

</body>
</html>
